package com.example.demo.dao;

import com.example.demo.model.LaterView;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

/**
 * @author sun
 */
public interface LaterViewMapper {
    /**
     * 根据主键删除 
     * @param id Integer
     * @return int
     */
    @Delete({
        "delete from later_view",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * 保存
     * @param record LaterView
     * @return int
     */
    @Insert({
        "insert into later_view (id, user_id, ",
        "news_id, create_time)",
        "values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, ",
        "#{newsId,jdbcType=INTEGER}, #{createTime,jdbcType=datetime})"
    })
    int insert(LaterView record);

    /**
     * 根据字段是否为空保存 
     * @param record LaterView
     * @return int
     */
    @InsertProvider(type=LaterViewSqlProvider.class, method="insertSelective")
    int insertSelective(LaterView record);

    /**
     * 根据主键查询 
     * @param id Integer
     * @return LaterView
     */
    @Select({
        "select",
        "id, user_id, news_id, create_time",
        "from later_view",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="news_id", property="newsId", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    LaterView selectByPrimaryKey(Integer id);

    /**
     * 根据字段是否为空更新 
     * @param record LaterView
     * @return int
     */
    @UpdateProvider(type=LaterViewSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(LaterView record);

    /**
     * 根据主键更新所有字段 
     * @param record LaterView
     * @return int
     */
    @Update({
        "update later_view",
        "set user_id = #{userId,jdbcType=INTEGER},",
          "news_id = #{newsId,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=datetime}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(LaterView record);
}